Skip to content

fix(tron): Enhance Tron direct transaction signing and address security issues#4737

Merged
sergei-boiko-trustwallet merged 13 commits intomasterfrom
fix/tron-raw-json-signing
Apr 23, 2026
Merged

fix(tron): Enhance Tron direct transaction signing and address security issues#4737
sergei-boiko-trustwallet merged 13 commits intomasterfrom
fix/tron-raw-json-signing

Conversation

@sergei-boiko-trustwallet
Copy link
Copy Markdown
Contributor

This pull request introduces significant improvements to the Tron transaction signing logic, focusing on robust handling, validation, and deserialization of raw JSON transactions. The changes remove legacy direct signing by txID, enforce strict checks on transaction hashes, and add comprehensive error reporting for malformed or tampered transactions. Additionally, the codebase is refactored to use a more structured and safer approach for handling raw JSON transactions across the signing, compiling, and preimage generation flows.

Key changes include:

Raw JSON Transaction Handling and Validation

  • Added new deserialization and validation logic for raw JSON transactions, ensuring that the provided txID matches the hash of both raw_data_hex and the serialized transaction. Detailed error codes and messages are returned for mismatches or unsupported cases.

  • The raw_json field in SigningInput is now the preferred way to provide transactions for signing; the legacy txId field and related direct sign logic have been removed.

Error Handling and Reporting

  • Introduced a new error code, Error_tx_hash_mismatch, for cases where the transaction hash does not match the derived hash from the raw transaction data, improving diagnostics for tampered or malformed transactions.

  • Improved error propagation and reporting throughout the signing and preimage generation flows, returning detailed messages and codes in the output proto.

Test and API Updates

  • Updated and added tests to cover the new raw JSON signing path, and removed legacy direct signing tests using txId.

Internal Refactoring

  • Refactored the preimage and signing output logic to use structured result types, improving maintainability and clarity.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens Tron transaction signing by shifting the “direct signing” flow to a validated raw_json input, introducing JSON deserialization back into the internal Tron protobuf transaction format, and adding a new error code for tx-hash mismatches.

Changes:

  • Removed legacy direct signing via txId and made SigningInput.raw_json the preferred direct-signing input with txID/hash validation.
  • Added Tron JSON deserialization (transactionFromJSON) plus extensive test coverage for raw JSON signing and validation failures.
  • Updated preimage/signing/compilation flows to return structured outputs (including tx compiler pre-signing output).

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/chains/Tron/TransactionCompilerTests.cpp Splits out invalid raw JSON compile test case.
tests/chains/Tron/SignerTests.cpp Reworks tests around raw JSON signing + adds tx-hash mismatch / unsupported cases.
tests/chains/Tron/DeserializationTests.cpp New unit tests for JSON → internal transaction deserialization round-trips and invalid inputs.
swift/Tests/Blockchains/TronTests.swift Removes txID-direct signing test; adds raw JSON signing test.
src/proto/Tron.proto Removes legacy txId; documents raw_json behavior and expected errors.
src/proto/Common.proto Adds Error_tx_hash_mismatch.
src/Tron/Signer.h Adds raw JSON signing/compile/preimage APIs and structured preimage output type.
src/Tron/Signer.cpp Implements raw JSON validation/signing/compilation and structured preimage output.
src/Tron/Entry.cpp Updates preimage flow to use structured pre-signing output.
src/Tron/Deserialization.h / .cpp Adds JSON deserialization into protocol::Transaction for supported contract types.
rust/tw_proto/src/impls.rs Adds display string for the new signing error.
android/.../TestTronTransactionSigner.kt Removes txId-direct signing test; adds raw JSON signing test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Tron/Signer.cpp
Comment thread src/Tron/Signer.cpp
Comment thread src/Tron/Signer.cpp
Comment thread src/Tron/Signer.cpp
Comment thread src/Tron/Signer.cpp
Comment thread src/proto/Tron.proto Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 17, 2026

Binary size comparison

➡️ aarch64-apple-ios:

- 14.36 MB
+ 14.36 MB 	 +1 KB

➡️ aarch64-apple-ios-sim: 14.37 MB

➡️ aarch64-linux-android:

- 18.80 MB
+ 18.81 MB 	 +1 KB

➡️ armv7-linux-androideabi:

- 16.23 MB
+ 16.23 MB 	 +1 KB

➡️ wasm32-unknown-emscripten:

- 13.72 MB
+ 13.72 MB 	 +1 KB

BSCSecChef
BSCSecChef previously approved these changes Apr 22, 2026
Copy link
Copy Markdown
Collaborator

@BSCSecChef BSCSecChef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Size check is added across and for the empty check in serialization - if crafted json is passed which has all empty values, but even if one element is passed, searlizeAsString will have non-empty bytes and not match he txID.

Changes look good

Comment thread src/Tron/Deserialization.cpp Outdated
Comment thread src/Tron/Deserialization.cpp Outdated
Comment thread src/Tron/Deserialization.cpp Outdated
Comment thread src/Tron/Deserialization.cpp
Comment thread src/Tron/Deserialization.cpp Outdated
@BSCSecChef
Copy link
Copy Markdown
Collaborator

LGTM

@sergei-boiko-trustwallet sergei-boiko-trustwallet merged commit cfebc74 into master Apr 23, 2026
15 of 17 checks passed
@sergei-boiko-trustwallet sergei-boiko-trustwallet deleted the fix/tron-raw-json-signing branch April 23, 2026 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants